#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
int n, m; int rem; long long sum;
struct farmer
{
	int price;
	int litre;
}far[5005];
int compare(const void* p1, const void* p2)
{
	if (((struct farmer*)p1)->price < ((struct farmer*)p2)->price)
		return -1;
	else if (((struct farmer*)p1)->price > ((struct farmer*)p2)->price)
		return 1;
	else {
		if (((struct farmer*)p1)->litre < ((struct farmer*)p2)->litre)
			return 1;
		else return -1;
	}
}
int main()
{
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		scanf("%d%d", &far[i].price, &far[i].litre);
	}
	qsort(far, m, sizeof(struct farmer), compare);
	while (n > 0) {
		if (n >= far[rem].litre) {
			sum += far[rem].litre * far[rem].price;
			n -= far[rem++].litre;
		}
		else {
			sum += far[rem].price * n;
			n -= n;
		}
	}
	cout << sum;
	return 0;
}
